function buttonFormatter(value, row,index) {
    var d = "<button id='btn_edit' type='button' onclick='_update("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修 改</button>";
    d += "<button id='btn_edit' type='button' onclick='deleteEmp("+row.rowId+", "+row.fbFlag+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>&nbsp;删&nbsp;除&nbsp;</button>";
	// if (row.useFlag==0) { //启用
	//    e = "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.useFlag+", \""+row.title+"\");'    class='btn btn-default btn-sm'><span class='glyphicon glyphicon-ok'></span>启 用</button>";
	// } else { // 停用
	//    e = "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.useFlag+", \""+row.title+"\");'    class='btn btn-default btn-sm'><span class='glyphicon glyphicon-stop'></span>停 用</button>";
	// }
	//var caozuo3 = "<button id='btn_edit' type='button' onclick='checkContent("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>查看攻略内容</button>";
    return d;
}

function hotFlagFormatter(value, row) {
	if (row.hotFlag == 1) {
		return ' <span class="text-success">是 </span>';
	} else if (row.hotFlag == 0) {
		return ' <span class="text-warning">否 </span>';
	}
}
function fbFlagFormatter(value, row) {
    var html = "";
    if (row.fbFlag == 1) {
        html = "<span class='text-success'>发布中 </span>&nbsp;&nbsp;&nbsp;&nbsp;"
        html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.fbFlag+", \""+row.raiderTitle+ "\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-stop'></span>停用</button>";
    } else {
        html = "<span class='text-warning'>停用中 </span>&nbsp;&nbsp;&nbsp;&nbsp;";
        html += "<button id='btn_edit' type='button' onclick='_stop("+row.rowId+", "+row.fbFlag+", \""+row.raiderTitle+ "\");'    class='btn btn-default btn-sm '><span class='glyphicon glyphicon-ok'></span>发布</button>";
    }
    return html;
}
// 加载table 数据
$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    $("#dataTable").bootstrapTable({ 
    	url: JSSTRATEGYV1 + "/raiderManage/getRaiderManageList",
    	method:"get",
        contentType: "application/x-www-form-urlencoded",
    	pagination:true,
    	sidePagination:"server",
    	queryParams: function(params) {
            return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
        }
	}); 
})
var tableIndex = 0; // 添加修改的弹出框的ID
  // 弹出添加的窗口
function add(){
    tableIndex = layer.open({
 	  	type: 2,
	 	title: "添加游戏攻略",
 	  	closeBtn: 1,
 	  	shadeClose: true,
 	  	area: ['800px', '700px'],
 	  	content: JSSYSMANAGERV1 + '/raiderManage/toAddRaiderManage?rowId=0',
 	  	btn: ["确 认","关 闭"], 
 	  	yes: function(index, layero){
	    	var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
	        iframeWin.add();
		}
	});
}
// 弹出添加的窗口      修改功能
function _update(rowId){
    tableIndex = layer.open({
 	  	type: 2,
 	  	title: "修改游戏攻略",
 	  	closeBtn: 1,
 	  	shadeClose: true,
 	  	area: ['800px', '700px'],
 	  	content: JSSYSMANAGERV1 + '/raiderManage/toAddRaiderManage?rowId='+rowId,
 	  	btn: ["确 认","关 闭"], 
 	  	yes: function(index, layero) {
	    	var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
	        iframeWin.add();
		}
	});
}

//删除攻略
function deleteEmp(rowId, fbFlag){
    layer.confirm("您确认【删除】?", {btn: ['确认', '取消']},
        function(){
            $.ajax({
                url: JSSTRATEGYV1 + "/raiderManage/delete",
                type: "post",
                cache: false,
                data: {rowId:rowId, fbFlag:fbFlag, token: sessionStorage.getItem("token")},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data == 1) {
                        layer.msg("删除成功", {icon: 1});
                        findData();
                    } else if (data == 3) {
                        layer.msg("删除失败，该攻略启用中");
                    } else if(data == "-2"){
                        window.location.href=JSCTX;
                    } else {
                        layer.msg(data, {icon: 5});
                    }
                }
            });
        });
}
//  启用/停用
function _stop(rowId, fbFlag, raiderTitle){
    var descStr = '【停用】<a style="color:red">'+'"'+raiderTitle+'"'+'</a>';
    if (fbFlag == 0) {
        descStr = '【启用】<a style="color:red">'+'"'+raiderTitle+'"'+'</a>';
    }
    fbFlag = Math.abs(Number(fbFlag) - 1);
    layer.confirm('您确认'+descStr+'吗？', {btn: ['确认', '取消']},
        function(){
            if (rowId == null || rowId == "") {
                layer.msg("id不能为空!");
                return;
            }
            $.ajax({
                url: JSSTRATEGYV1 + "/raiderManage/updateFbFlag",
                type: "post",
                cache: false,
                data: {rowId:rowId, fbFlag:fbFlag, token: sessionStorage.getItem("token")},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data == 1) {
                        layer.msg(descStr+"成功", {icon: 1});
                        findData();
                    } else if(data == "-2"){
                        window.location.href="${sysManagerV1}/";
                    } else {
                        layer.msg(descStr+"失败", {icon: 5});
                    }
                }
            });
        });
}
// //查看攻略内容
// /*function checkContent(rowId){
// 	window.location.href="/tlzsGameStrategy/checkContent?rowId="+rowId;
// }*/
// function checkContent(rowId){
// 	layer.open({
//  	  	type: 2,
//  	  	title: "攻略详情查看",
//  	  	closeBtn: 1,
//  	  	shadeClose: true,
//  	  	area: ['400px', '480px'],
//  	  	content: '/tlzsGameStrategy/checkContent?rowId='+rowId,
//  	  	btn: ["关 闭"]
// 	});
// }
function findData(){
   $("#dataTable").bootstrapTable("refresh",{} ); 
}

/*bootstrap table点击行事件*/
$(function(){
	 $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})